/**
 * 
 */
package cl.inmotion.support.bitacora.view.servlets.reportes;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cl.inmotion.support.bitacora.dao.RegistroDAO;

/**
 * @author Andres Farias
 * 
 */
@WebServlet("/reportes")
public class ReportesServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		List<RegistroDAO> registros;
		try {
			registros = RegistroDAO.findRegistros();
		} catch (SQLException e) {
			req.setAttribute("errorMsg", "Ha ocurrido un problema al tratar de recuperar la lista de todos los registros.");
			registros = new ArrayList<RegistroDAO>();
		}
		
		req.setAttribute("registros", registros);
		
		/* Se reenvia a la pagina principal de reportes */
		req.getRequestDispatcher("/WEB-INF/jsp/reportes/Reportes.jsp").forward(
				req, resp);

	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		this.doGet(req, resp);
	}
}
